import {
    deepClone2
} from "@/utils/tool.js";
/**
 * sku组合
 * @params sizeData 尺码数组 ['00-00-00']
 * @params colorData 颜色序号数组 ['A','B']
 */
export const setSku = (sizeData1 = [], colorData1 = []) => {
    let sizeData = Array.from(new Set(sizeData1));
    let colorData = Array.from(new Set(colorData1));
    let list = sizeData.reduce((pre, cur, index) => {
        let ll = colorData.map((item) => {
            return cur + " " + item;
        });
        return pre.concat(ll);
    }, []);
    return list;
};
/**
 * 按颜色尺码查看 <== 按配件查看
 * @params treeData2 按配件组合的树结构数据
 * @params colorData 规格颜色列表
 * @retrun treeData1 按sku组合树结构数据
 */
export const changePartsToSkuFun = (treeData22, colorData) => {
    console.log("2==>1")
    let treeData2 = deepClone2(treeData22)
    let colorL = deepClone2(colorData)
    let partsList = []
    for (let i = 0; i < treeData2.length; i++) {
        for (let j = 0; j < treeData2[i].children.length; j++) {
            const partsItem = deepClone2(treeData2[i].children[j]); // 配件
            const item1 = Object.assign({}, partsItem)
            item1['accessoryName'] = partsItem.label // 配件名称
            item1['accessoryType'] = treeData2[i].label // 齋架/配件
            item1['level'] = "1"
            item1['children'] = []
            if (partsItem.children && partsItem.children.length > 0) {
                item1["children"] = [];
                partsItem.children.forEach((childItem) => {
                    const item2 = Object.assign({}, childItem)
                    if (item2.children) item2.children = []
                    item2['accessoryName'] = childItem.label // 配件名称
                    // item2['accessoryType'] = treeData2[i].accessoryType // 齋架/配件
                    item2['level'] = "2"
                    item1["children"].push(item2);
                });
            }
            partsList.push(item1);
        }
    }
    // console.log("partsList", partsList)
    const uniqueSizeColorObj = {};
    // 将对象转换成数组
    const uniqueSizeColors = [{
        label: "未关联尺码颜色",
        cate: "title1",
        ida: 'mm',
        children: [{
                label: "齋架",
                cate: "title2",
                ida: 'mm-1',
                children: [],
            },
            {
                label: "配件",
                num: "",
                ida: 'mm-2',
                cate: "title2",
                children: [],
            },
        ],
    }];
    let partsList1 = partsList.filter(item => {
        return item.accessoryType == "斋架" || item.accessoryType == "齋架"
    })
    let partsList2 = partsList.filter(item => {
        return item.accessoryType == "配件"
    })
    // 配件
    partsList2.map((partsItem) => {
        let sizeListCheck = partsItem.sizeListCheck || [];
        let colorListCheck = partsItem.colorListCheck?.length == 0 ? [] : partsItem.colorListCheck
        let sizeListCheckAll = sizeListCheck
        if (sizeListCheck.length == 0 && partsItem.includedAngleList.length > 0 && partsItem.colorListCheck.length > 0) {
            sizeListCheckAll = partsItem.includedAngleList
        }
        sizeListCheckAll.forEach((sizeItem, index) => {
            colorListCheck.forEach((color) => {
                const key = sizeItem + " " + color;
                if (!uniqueSizeColorObj[key]) {
                    uniqueSizeColorObj[key] = {};
                    uniqueSizeColorObj[key].children = [];
                }
                if (!uniqueSizeColorObj[key].children[0]) {
                    uniqueSizeColorObj[key].children[0] = {
                        label: "齋架",
                        cate: "title2",
                        ida: 'mm-1' + index + key,
                        children: [],
                    };
                }
                if (!uniqueSizeColorObj[key].children[1]) {
                    uniqueSizeColorObj[key].children[1] = {
                        label: "配件",
                        cate: "title2",
                        ida: 'mm-2' + index + key,
                        children: [],
                    };
                }
                let obj = resPartsItem(partsItem)
                if (partsItem.accessoryType === "配件") {
                    uniqueSizeColorObj[key].children[1].children.push(obj);
                }
            });
        });
        if (partsItem.accessoryType === "配件" && (sizeListCheck.length == 0 && partsItem.includedAngleList.length == 0) || colorListCheck.length == 0) {
            let obj = resPartsItem(partsItem)
            uniqueSizeColors[0].children[1].children.push(obj)
        }
    });
    // 齋架
    partsList1.map((partsItem) => {
        let sizeListCheck = partsItem.sizeListCheck || [];
        let colorListCheck = colorL
        let sizeListCheckAll = sizeListCheck
        if (sizeListCheck.length == 0 && partsItem.includedAngleList.length > 0) {
            sizeListCheckAll = partsItem.includedAngleList
        }
        let obj = resPartsItem(partsItem)
        sizeListCheckAll.forEach((sizeItem, index) => {
            // let skuList2 = Object.keys(uniqueSizeColorObj).filter(key1 => {
            //     return key1.split(" ")[0] == sizeItem
            // })
            // if (skuList2.length > 0) {
            //     skuList2.forEach(key2 => {
            //         if (!uniqueSizeColorObj[key2].children[0]) {
            //             uniqueSizeColorObj[key2].children[0] = {
            //                 label: "齋架",
            //                 cate: "title2",
            //                 ida: 'mm-1' + index + key2,
            //                 children: [],
            //             };
            //         }
            //         uniqueSizeColorObj[key2].children[0].children.push(obj)
            //     })
            // } else {
            colorListCheck.forEach((color) => {
                const key = sizeItem + " " + color;
                if (!uniqueSizeColorObj[key]) {
                    uniqueSizeColorObj[key] = {};
                    uniqueSizeColorObj[key].children = [];
                }
                if (!uniqueSizeColorObj[key].children[1]) {
                    uniqueSizeColorObj[key].children[1] = {
                        label: "配件",
                        cate: "title2",
                        ida: 'mm-2' + index + key,
                        children: [],
                    };
                }
                if (!uniqueSizeColorObj[key].children[0]) {
                    uniqueSizeColorObj[key].children[0] = {
                        label: "齋架",
                        cate: "title2",
                        ida: 'mm-1' + index + key,
                        children: [],
                    };
                }
                if (partsItem.accessoryType === "斋架" || partsItem.accessoryType === "齋架") {
                    uniqueSizeColorObj[key].children[0].children.push(obj);
                }
            });
            // }
        });
        if ((partsItem.accessoryType === "斋架" || partsItem.accessoryType === "齋架") && (sizeListCheck.length == 0 && partsItem.includedAngleList.length == 0) || colorListCheck.length == 0) {
            let obj = resPartsItem(partsItem)
            uniqueSizeColors[0].children[0].children.push(obj)
        }
    });
    /*****ceshi-end*****/

    for (let key in uniqueSizeColorObj) {
        uniqueSizeColors.push({
            label: key,
            cate: "title1",
            ida: key,
            children: uniqueSizeColorObj[key]?.children || [],
        });
    }
    uniqueSizeColors.sort((a, b) => {
        if (a.label == '未关联尺码颜色' || b.label == '未关联尺码颜色') {
            return 1;
        }
        return a.label.localeCompare(b.label);
    });
    return uniqueSizeColors;

}
/**
 * 按颜色尺码查看 ==> 按配件查看
 * @parasm treeData1 按sku组合的树结构数据
 * @return treeData2 按配件组合的树结构数据
 */
export const changeSkuToPartsFun = (treeData11) => {
    console.log("1==>2")
    let treeData1 = deepClone2(treeData11)
    // 初始化树
    let treeData2 = [{
            label: "齋架",
            cate: "title1",
            children: [],
        },
        {
            label: "配件",
            cate: "title1",
            children: [],
        },
    ];
    let list1 = []; // 所有齋架
    let list2 = []; // 所有配件
    // let obj = ;
    treeData1.forEach((item) => {
        if (!item.children[0].children) {
            item.children[0].children = [];
        }
        // 所有齋架  -- 元素循环
        item.children[0].children.forEach((res) => {
            if (item.label == "未关联尺码颜色") {
                let p = JSON.parse(JSON.stringify(res))
                p['colorListCheck'] = []
                p['sizeListCheck'] = res.sizeListCheck ? [...res.sizeListCheck] : []
                p['includedAngleList'] = res.includedAngleList ? [...res.includedAngleList] : []
                list1.push(p);
            } else {
                // 已关联颜色尺码
                let index = list1.findIndex((part) => {
                    // return skuItem.children[0].labelNum == res.labelNum;
                    return part.ida == res.ida;
                });
                let s = item.label.split(" ")[0]; // 尺码
                let c = item.label.split(" ")[1]; // 颜色
                // 夹角
                if (s.split('-').length == 1) {
                    // 不在配件列表中
                    if (index == -1) {
                        let p = JSON.parse(JSON.stringify(res))
                        p['colorListCheck'] = []
                        p['sizeListCheck'] = []
                        p['accessoryName'] = res.label
                        list1.push(p)
                    } else {
                        list1[index]['colorListCheck'] = []
                        list1[index]['sizeListCheck'] = []
                        list1[index].includedAngleList = Array.from(
                            new Set(list1[index].includedAngleList)
                        );
                    }
                } else {
                    // 不在配件列表中
                    if (index == -1) {
                        let p = JSON.parse(JSON.stringify(res));
                        p['colorListCheck'] = []
                        p['sizeListCheck'] = [s]
                        p['accessoryName'] = res.label
                        list1.push(p)
                    } else {
                        // 在配件列表中
                        // list1[index].colorListCheck.push(c);
                        list1[index].sizeListCheck.push(s);
                        // list1[index].colorListCheck = Array.from(
                        //     new Set(list1[index].colorListCheck)
                        // );
                        list1[index].sizeListCheck = Array.from(
                            new Set(list1[index].sizeListCheck)
                        );
                        list1[index].includedAngleList = Array.from(
                            new Set(list1[index].includedAngleList)
                        );
                    }
                }
            }
        });
        if (!item.children[1].children) {
            item.children[1].children = [];
        }
        // 所有配件 -- 元素循环
        item.children[1].children.forEach((res) => {
            if (item.label == "未关联尺码颜色") {
                let p = JSON.parse(JSON.stringify(res))
                p['colorListCheck'] = res.colorListCheck ? [...res.colorListCheck] : []
                p['sizeListCheck'] = res.sizeListCheck ? [...res.sizeListCheck] : []
                p['includedAngleList'] = res.includedAngleList ? [...res.includedAngleList] : []
                p['accessoryName'] = res.label
                list2.push(p);
            } else {
                // 已关联颜色尺码
                let index = list2.findIndex((part) => {
                    return part.ida == res.ida;
                });
                let s = item.label.split(" ")[0]; // 尺码
                let c = item.label.split(" ")[1]; // 颜色
                // 夹加
                if (s.split('-').length == 1) {
                    // 不在配件列表中
                    if (index == -1) {
                        let p = JSON.parse(JSON.stringify(res))
                        p['colorListCheck'] = [c]
                        p['sizeListCheck'] = []
                        p['accessoryName'] = res.label
                        list2.push(p);
                    } else { // 配件列表中
                        // 在配件列表中，增加尺码和颜色复选值
                        list2[index].colorListCheck.push(c);
                        list2[index].colorListCheck = Array.from(
                            new Set(list2[index].colorListCheck)
                        );
                        list2[index].sizeListCheck = [];
                        list2[index].includedAngleList = Array.from(
                            new Set(list2[index].includedAngleList)
                        );
                    }
                } else {
                    // 不在配件列表中
                    if (index == -1) {
                        let p = JSON.parse(JSON.stringify(res))
                        p['colorListCheck'] = [c]
                        p['sizeListCheck'] = [s]
                        p['accessoryName'] = res.label
                        list2.push(p)
                    } else { // 配件列表中
                        // 在配件列表中，增加尺码和颜色复选值
                        list2[index].colorListCheck.push(c);
                        list2[index].sizeListCheck.push(s);
                        list2[index].colorListCheck = Array.from(
                            new Set(list2[index].colorListCheck)
                        );
                        list2[index].sizeListCheck = Array.from(
                            new Set(list2[index].sizeListCheck)
                        );
                        list2[index].includedAngleList = Array.from(
                            new Set(list2[index].includedAngleList)
                        );
                    }
                }
            }
        });
        // 所有配件  -- 元素循环
        // list2 = list2.concat(item.children[1].children);
    });
    list1.sort((a, b) => {
        if (a.listOrder !== b.listOrder) {
            return a.listOrder - b.listOrder;
        } else if (a.componentNum + a.colorNum !== b.componentNum + b.colorNum) {
            let a1 = (a.componentNum || '') + (a.colorNum || '')
            let b1 = (b.componentNum || '') + (b.colorNum || '')
            return a1.localeCompare(b1);
        }
    });
    list2.forEach(item => {
        if (item.colorListCheck && item.colorListCheck.length > 0) {
            item.colorListCheck.sort((a, b) => {
                return a.localeCompare(b)
            })
        }
    })
    list2.sort((a, b) => {
        if (a.listOrder !== b.listOrder) {
            return a.listOrder - b.listOrder;
        } else if (a.componentNum + a.colorNum !== b.componentNum + b.colorNum) {
            let a1 = (a.componentNum || '') + (a.colorNum || '')
            let b1 = (b.componentNum || '') + (b.colorNum || '')
            return a1.localeCompare(b1);
        } else {
            let a2 = a.colorListCheck ? a.colorListCheck.join('') : ''
            let b2 = b.colorListCheck ? b.colorListCheck.join('') : ''
            return a2.localeCompare(b2);
        }
    });
    treeData2[0].children = list1;
    treeData2[1].children = list2;
    // console.log("tree", treeData2)
    return treeData2
}

export const resPartsItem = (item) => {
    let item1 = {
        label: item.accessoryName,
        level: '1',
        accessoryType: item.accessoryType,
        orderType: item.orderType,
        componentNum: item.componentNum, //元件编号-主档编号
        colorNum: item.colorNum, //元件编号-颜色编号
        sizeNum: item.sizeNum, // 尺码
        sapDesc: item.sapDesc, // 物料说明
        appearanceSpec: item.appearanceSpec, // 外观规格
        num: item.num, // 单位
        unit: item.unit,
        groupDesc: item.groupDesc,
        group: item.group,
        includedAngleList: item.includedAngleList ? [...item.includedAngleList] : [],
        colorListCheck: item.colorListCheck ? [...item.colorListCheck] : [],
        sizeListCheck: item.sizeListCheck ? [...item.sizeListCheck] : [],
        note: item.note,
        is_na: item.is_na,
        ida: item.ID ? item.ID : item.ida,
        ID: item.ID,
        listOrder: item.listOrder || 0,
        materialProperty: item.materialProperty || "", // 材质属性
        workingProcedure: item.workingProcedure || "", // 工序
        isSpleenMetalShare: item.isSpleenMetalShare || "", // 是否辨别金胶共用
        sapDelete: item.sapDelete || 0, // 已汇入sap
        isNew: item.isNew || '0',
        editUnit: item.editUnit || '0',
        editSapDesc: item.editSapDesc || '0',
        editGroupDesc: item.editGroupDesc || '0',
        err: item.err || '',
    };
    if (item.children && item.children.length > 0) {
        item1["children"] = [];
        item.children.forEach((item2) => {
            item1["children"].push({
                label: item2.accessoryName,
                level: '2',
                accessoryType: item2.accessoryType,
                orderType: item2.orderType,
                componentNum: item2.componentNum, //元件编号-主档编号
                colorNum: item2.colorNum, //元件编号-颜色编号
                sizeNum: item2.sizeNum,
                sapDesc: item2.sapDesc,
                appearanceSpec: item2.appearanceSpec,
                num: item2.num,
                unit: item2.unit,
                groupDesc: item2.groupDesc,
                group: item2.group,
                note: item2.note,
                is_na: 0,
                ida: item2.ID ? item2.ID : item2.ida,
                ID: item2.ID,
                listOrder: item2.listOrder || 0,
                parentId: item2.parentId,
                materialProperty: item2.materialProperty || "", // 材质属性
                workingProcedure: item2.workingProcedure || "", // 工序
                isSpleenMetalShare: item2.isSpleenMetalShare || "", // 是否辨别金胶共用
                sapDelete: item2.sapDelete || 0, // 已汇入sap
                isNew: item2.isNew || '0',
                editUnit: item2.editUnit || '0',
                editSapDesc: item2.editSapDesc || '0',
                editGroupDesc: item2.editGroupDesc || '0',
                err: item2.err || '',
            });
        });
    }
    return item1;
};
/**
 * 返回的数据转换为treeData2
 * @parasm resdata 按sku组合的树结构数据
 * @return treeData2
 */
export const resDataToTreeData2 = (partsList) => {
    let partsList1 = []; // 所有齋架
    let partsList2 = []; // 所有配件
    partsList = partsList.map(part => {
        let sizeL = part.sizeList?.map(s => {
            return s.sizeNum
        })
        part['label'] = part.accessoryName;
        part['includedAngleList'] = part.includedAngleList ? [...part.includedAngleList] : [];
        part['colorListCheck'] = part.colorList ? [...part.colorList] : [];
        part['sizeListCheck'] = sizeL ? sizeL : [];
        part['ida'] = part.ID ? part.ID : part.ida;
        part['listOrder'] = part.listOrder || 0;
        // 自制新保存后锁定 物料说明 单位 物料群组
        if (part.orderType && part.orderType == '自制/新' && !part.sapDesc) {
            part["editSapDesc"] = "1";
        }
        if (part.orderType && part.orderType == '自制/新' && !part.unit) {
            part["editUnit"] = "1";
        }
        if (part.orderType && part.orderType == '自制/新' && !part.groupDesc) {
            part["editGroupDesc"] = "1";
        }
        if (part.children && part.children.length > 0) {
            part.children.forEach((item2) => {
                item2['label'] = item2.accessoryName
                item2['includedAngleList'] = []
                item2['colorListCheck'] = []
                item2['sizeListCheck'] = []
                item2['ida'] = item2.ID ? item2.ID : item2.ida
            });
        } else {
            part['children'] = []
        }
        return part
    })
    partsList1 = partsList.filter(item => {
        return item.accessoryType == "斋架" || item.accessoryType == "齋架"
    })
    partsList1.sort((a, b) => {
        let a1 = (a.componentNum || '') + (a.colorNum || '')
        let b1 = (b.componentNum || '') + (b.colorNum || '')
        if (a.listOrder !== b.listOrder) {
            return a.listOrder - b.listOrder;
        } else if (a1 !== b1) {
            return a1.localeCompare(b1);
        }
    });
    partsList2 = partsList.filter(item => {
        return item.accessoryType == "配件"
    })
    partsList2.forEach(item => {
        if (item.colorListCheck && item.colorListCheck.length > 0) {
            item.colorListCheck.sort((a, b) => {
                return a.localeCompare(b)
            })
        }
    })
    // partsList2.sort((a, b) => {
    //     let c1 = ''
    //     let c2 = ''
    //     if (a.colorListCheck && a.colorListCheck[0]) {
    //         c1 = a.colorListCheck[0]
    //     }
    //     if (b.colorListCheck && b.colorListCheck[0]) {
    //         c2 = b.colorListCheck[0]
    //     }
    //     let a1 = (a.componentNum || '') + (a.colorNum || '')
    //     let b1 = (b.componentNum || '') + (b.colorNum || '')
    //     if (a.listOrder !== b.listOrder) {
    //         return a.listOrder - b.listOrder;
    //     } else if (c1 != c2) {
    //         return c1.localeCompare(c2);
    //     } else if (a1 != b1) {
    //         return a1.localeCompare(b1);
    //     }
    //     // else if (a.componentNum + a.colorNum && b.componentNum + b.colorNum) {
    //     //     let a1 = (a.componentNum || '') + (a.colorNum || '')
    //     //     let b1 = (b.componentNum || '') + (b.colorNum || '')
    //     //     if (a.componentNum + a.colorNum == b.componentNum + b.colorNum) {
    //     //         return c1.localeCompare(c2);
    //     //     } else {
    //     //         return a1.localeCompare(b1);
    //     //     }
    //     // }
    //     // else if (a.componentNum + a.colorNum !== b.componentNum + b.colorNum) {
    //     //     let a1 = (a.componentNum || '') + (a.colorNum || '')
    //     //     let b1 = (b.componentNum || '') + (b.colorNum || '')
    //     //     return a1.localeCompare(b1);
    //     // }
    // });
    let treeData2 = [{
            label: "齋架",
            cate: "title1",
            children: partsList1,
        },
        {
            label: "配件",
            cate: "title1",
            children: partsList2,
        },
    ];
    return treeData2
}


// 测试标准列表树获取
export const getTestList = (tree) => {
    let list = []
    tree.forEach((level1, index1) => {
        level1.children.forEach((level2, index2) => {
            level2.children.forEach((level3, index3) => {
                let obj = {}
                obj['isCheck'] = level1.isCheck || level2.isCheck || level3.isCheck || false
                obj['iscsCheck'] = level1.iscsCheck || level2.iscsCheck || level3.iscsCheck || false
                obj['isdbCheck'] = level1.isdbCheck || level2.isdbCheck || level3.isdbCheck || false
                level3['isCheck'] = obj.isCheck
                if (level3.children) {
                    level3.children.forEach(level4 => {
                        if (level4.iscsCheck) {
                            obj['iscsCheck'] = level4.iscsCheck
                        }
                        if (level4.isdbCheck) {
                            obj['isdbCheck'] = level4.isdbCheck
                        }
                    })
                }
                let checkL = level2.children.filter(item=>{
                    return item.isCheck
                })
                if (level1.title == '結構測試') {
                    obj['testName'] = level1.name + ">" + level2.name;
                } else if(checkL.length == level2.children.length){
                    obj['testName'] = level1.name + ">" + level2.name;
                } 
                else {
                    obj['testName'] = level1.name + ">" + level2.name + ">" + level3.name;
                }
                if (obj.isCheck && obj.isdbCheck) {
                    list.push(obj)
                }
            })
        })
    })
    // 去重
    let list2 = []
    list.forEach(res => {
        let i = list2.findIndex(item => {
            return item.testName == res.testName
        })
        if (i == -1) {
            list2.push(res)
        }
    })
    return list2
}

// 删除树ID
export const delTreeID = (list) => {
    list.forEach((item, i) => {
        if (item.ID) delete item.ID;
        if (item.children && item.children.length > 0) {
            delTreeID(item.children)
        }
    })

}

/**
 * 返回的数据转换为treeData1
 * @parasm resdata 按sku组合的树结构数据
 * @return treeData1
 */
export const resDataToTreeData1 = (partsList, colorL) => {
    const uniqueSizeColorObj = {};
    // 将对象转换成数组
    const uniqueSizeColors = [{
        label: "未关联尺码颜色",
        cate: "title1",
        ida: 'mm',
        children: [{
                label: "齋架",
                cate: "title2",
                ida: 'mm-1',
                children: [],
            },
            {
                label: "配件",
                num: "",
                cate: "title2",
                ida: 'mm-2',
                children: [],
            },
        ],
    }];
    let partsList1 = partsList.filter(item => {
        return item.accessoryType == "斋架" || item.accessoryType == "齋架"
    })
    let partsList2 = partsList.filter(item => {
        return item.accessoryType == "配件"
    })
    // 配件
    partsList2.map((partsItem) => {
        let sizeList = partsItem.sizeList || [];
        let colorList = partsItem.colorList?.length == 0 ? [] : partsItem.colorList
        let sizeListAll = sizeList
        if (!partsItem.includedAngleList) {
            partsItem['includedAngleList'] = []
        }
        if (sizeList.length == 0 && partsItem.includedAngleList.length > 0 && partsItem.colorList.length > 0) {
            sizeListAll = partsItem.includedAngleList.map(r => {
                return {
                    sizeNum: r
                }
            })
        }
        sizeListAll.forEach((sizeItem, index) => {
            colorList.forEach((color) => {
                const key = sizeItem.sizeNum + " " + color;
                if (!uniqueSizeColorObj[key]) {
                    uniqueSizeColorObj[key] = {};
                    uniqueSizeColorObj[key].children = [];
                }
                if (!uniqueSizeColorObj[key].children[0]) {
                    uniqueSizeColorObj[key].children[0] = {
                        label: "齋架",
                        cate: "title2",
                        ida: 'mm-2' + index + key,
                        children: [],
                    };
                }
                if (!uniqueSizeColorObj[key].children[1]) {
                    uniqueSizeColorObj[key].children[1] = {
                        label: "配件",
                        cate: "title2",
                        ida: 'mm-1' + index + key,
                        children: [],
                    };
                }
                let obj = resPartsItem(partsItem)
                if (partsItem.accessoryType === "配件") {
                    uniqueSizeColorObj[key].children[1].children.push(obj);
                }
            });
        });
        if (partsItem.accessoryType === "配件" && (sizeList.length == 0 && partsItem.includedAngleList.length == 0) || colorList.length == 0) {
            let obj = resPartsItem(partsItem)
            obj['colorListCheck'] = partsItem.colorList ? [...partsItem.colorList] : [];
            let sList = []
            if (partsItem.sizeList) {
                sList = partsItem.sizeList.map((size) => {
                    return size.sizeNum;
                })
            }
            obj['sizeListCheck'] = sList || [];
            uniqueSizeColors[0].children[1].children.push(obj)
        }
    });
    // 齋架
    partsList1.map((partsItem) => {
        let sizeList = partsItem.sizeList || [];
        let colorList = colorL
        let sizeListAll = sizeList
        if (!partsItem.includedAngleList) {
            partsItem['includedAngleList'] = []
        }
        if (sizeList.length == 0 && partsItem.includedAngleList.length > 0) {
            sizeListAll = partsItem.includedAngleList.map(r => {
                return {
                    sizeNum: r
                }
            })
        }
        let obj = resPartsItem(partsItem)
        sizeListAll.forEach((sizeItem, index) => {
            // let skuList2 = Object.keys(uniqueSizeColorObj).filter(key1 => {
            //     return key1.split(" ")[0] == sizeItem.sizeNum
            // })
            // if (skuList2.length > 0) {
            //     skuList2.forEach(key2 => {
            //         if (!uniqueSizeColorObj[key2].children[0]) {
            //             uniqueSizeColorObj[key2].children[0] = {
            //                 label: "齋架",
            //                 cate: "title2",
            //                 ida: 'mm-1' + index + key2,
            //                 children: [],
            //             };
            //         }
            //         uniqueSizeColorObj[key2].children[0].children.push(obj)
            //     })
            // } else {
            colorList.forEach((color) => {
                const key = sizeItem.sizeNum + " " + color;
                if (!uniqueSizeColorObj[key]) {
                    uniqueSizeColorObj[key] = {};
                    uniqueSizeColorObj[key].children = [];
                }
                if (!uniqueSizeColorObj[key].children[1]) {
                    uniqueSizeColorObj[key].children[1] = {
                        label: "配件",
                        cate: "title2",
                        ida: 'mm-1' + index + key,
                        children: [],
                    };
                }
                if (!uniqueSizeColorObj[key].children[0]) {
                    uniqueSizeColorObj[key].children[0] = {
                        label: "齋架",
                        cate: "title2",
                        ida: 'mm-1' + index + key,
                        children: [],
                    };
                }
                if (partsItem.accessoryType === "斋架" || partsItem.accessoryType === "齋架") {
                    uniqueSizeColorObj[key].children[0].children.push(obj);
                }
            });
            // }
        });
        if ((partsItem.accessoryType === "斋架" || partsItem.accessoryType === "齋架") && (sizeList.length == 0 && partsItem.includedAngleList.length == 0) || colorList.length == 0) {
            let obj = resPartsItem(partsItem)
            obj['colorListCheck'] = partsItem.colorList ? [...partsItem.colorList] : [];
            let sList = []
            if (partsItem.sizeList) {
                sList = partsItem.sizeList.map((size) => {
                    return size.sizeNum;
                })
            }
            obj['sizeListCheck'] = sList || [];
            uniqueSizeColors[0].children[0].children.push(obj)
        }
    });

    for (let key in uniqueSizeColorObj) {
        uniqueSizeColors.push({
            label: key,
            cate: "title1",
            ida: key,
            children: uniqueSizeColorObj[key]?.children || [],
        });
    }
    uniqueSizeColors.sort((a, b) => {
        if (a.label == '未关联尺码颜色' || b.label == '未关联尺码颜色') {
            return 1;
        }
        return a.label.localeCompare(b.label);
    });
    return uniqueSizeColors;
}

/**
 * 返回的数据转换为num
 * @parasm 字符串
 * @return num
 */
 export const getChars = (str) => {
    var i = 0;
    var c = 0.0;
    var unicode = 0;
    var len = 0;
    if (str == null || str == "") {
        return 0;
    }
    len = str.length;
    for (i = 0; i < len; i++) {
        unicode = str.charCodeAt(i);
        if (unicode < 127) { //判断是单字符还是双字符
            c += 1;
        } else { //chinese
            c += 2;
        }
    }
    return c;
}